Crate safina[][src]

Expand description

crates.io version license: Apache 2.0 unsafe forbidden pipeline status

A safe Rust async runtime.

Features

  • forbid(unsafe_code)
  • Depends only on std
  • Good test coverage (>92%)

Limitations

Documentation

https://docs.rs/safina

safina_async_test has an #[async_test] macro for running async fn test functions.

Examples

let executor = safina::Executor::default();
let (sender, receiver) = std::sync::mpsc::channel();
executor.spawn(async move {
    sender.send(()).unwrap();
});
receiver.recv().unwrap();
let result = safina::block_on(async {
    prepare_request().await?;
    execute_request().await
})?;

Alternatives

  • smol
    • Popular
    • Contains generous amounts of unsafe code
  • async-std
    • Very popular
    • Contains generous amounts of unsafe code
  • futures
    • Very popular
    • Contains generous amounts of unsafe code
  • tokio
    • Very popular
    • Fast
    • Internally extremely complicated
    • Full of unsafe
  • bastion
    • Generous amounts of unsafe code
  • nostd_async

Changelog

  • v0.1.10 - block_on functions to take futures that are not Send.
  • v0.1.9 - Use once_cell by default.
  • v0.1.8 - Support stable with rust 1.51 and once_cell.
  • v0.1.7 - Add safina-net
  • v0.1.6 - Use safina-executor v0.1.3 API
  • v0.1.5 - Add safina_sync::Mutex
  • v0.1.4 - Upgrade to new safina-executor version which removes need for Box::pin.
  • v0.1.3 - Update docs
  • v0.1.2 - Renamed safina crate to safina-executor. Added new safina crate with re-exports, examples, and integration tests.
  • v0.1.1 - Add badges to readme
  • v0.1.0 - First published version

Happy Contributors 🙂

Fixing bugs and adding features is easy and fast. Send us a pull request and we intend to:

  • Always respond within 24 hours
  • Provide clear & concrete feedback
  • Immediately make a new release for your accepted change

TO DO

  • DONE - Make it work on Rust stable
  • Add an integration test
  • Add init function that starts worker threads and the timer thread.
  • Add an #[async_main] macro

Release Process

  1. Edit Cargo.toml and bump version number.
  2. Run ./release.sh

Structs

A future wrapper that returns DeadlineExceeded at a specified deadline.

A collection of threads for executing tasks and blocking jobs.

A wrapper around std::sync::Mutex with an async lock method.

An RAII scoped lock of a Mutex. It automatically unlocks the mutex when dropped (falls out of scope).

A Future that resolves when you call set on its clone.

A future that polls two futures and returns the value from the one that completes first.

A future that completes after the specified time.

Async wrapper around std::net::TcpListener.

Guard returned by set_thread_executor.

Call start_timer_thread to prevent this error.

Enums

  • DeadlineError::TimerThreadNotStarted
  • DeadlineError::DeadlineExceeded
  • Functions

    Executes the future on the current thread and returns its result.

    Executes the future on the current thread and returns its result.

    Gets the Executor from thread-local storage.

    Schedules f to run on any available thread in the blocking thread pool.

    Awaits both futures and returns the value from the one that completes first.

    Awaits the futures and returns the value from the one that completes first.

    Awaits the futures and returns the value from the one that completes first.

    Awaits the futures and returns the value from the one that completes first.

    Sets executor as the Executor for the current thread, saving it to thread-local storage.

    Returns duration time from now.

    Returns after deadline.

    Creates a new task to execute fut and schedules it for immediate execution.

    Creates a new task to execute fut and schedules it for immediate execution.

    Starts the worker thread, if it’s not already started. You must call this before calling sleep_until or sleep_for.

    Awaits inner, but returns DeadlineExceeded after deadline.

    Awaits inner, but returns DeadlineExceeded after duration time from now.